package com.dy.design_pattern_study.flyweight_pattern.dome3.factory;

import com.dy.design_pattern_study.flyweight_pattern.dome3.WebSite;
import com.dy.design_pattern_study.flyweight_pattern.dome3.impl.ConcreteWebSite;

import java.util.HashMap;
import java.util.Map;

/**
 * @CreateBy zhangdingyi
 * @Date 2023-04-23
 * @Content 网站工厂
 */
public class WebSiteFactory {
    private Map<String, WebSite> webSiteMap = new HashMap<>();

    //获得网站分类
    public WebSite getWebSiteCategory(String key){
        //如果存在则返回，不存在则创建返回
        if (!webSiteMap.containsKey(key)){
            webSiteMap.put(key, new ConcreteWebSite(key));
        }
        return webSiteMap.get(key);
    }

    //获得分类总数
    public int getWebSiteCount(){
        return webSiteMap.size();
    }
}
